package com.example.douyin.register;

import androidx.lifecycle.MutableLiveData;

import com.example.lib_base_mvvm.baseMVVM.BaseViewModel.BaseViewModel;
import com.example.lib_base_mvvm.entity.UserEntity;
import com.example.lib_base_mvvm.utils.ConstantsUtils;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RegisterViewModel extends BaseViewModel<RegisterRepo> {
    @Override
    protected RegisterRepo createRepo() {
        return new RegisterRepo();
    }
    public MutableLiveData<UserEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> fail = new MutableLiveData<>();
    public void register(String name,String pwd,String repwd){
        Map<String,String> map = new HashMap<>();
        map.put(ConstantsUtils.PARAM_USERNAME,name);
        map.put(ConstantsUtils.PARAM_PASSWORD,pwd);
        map.put(ConstantsUtils.PARAM_REPASSWORD,repwd);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(ConstantsUtils.PARAM_TYPE_JSON),s);

        repo.register(body,success,fail);
    }
}
